/*************************************************************************
	> File Name: 004.链式前向星.cpp
	> Author: Maureen 
	> Mail: Maureen@qq.com 
	> Created Time: 二  5/18 18:01:02 2021
 ************************************************************************/

#include <iostream>
#include <cstring>
using namespace std;

//head数组: 记录以 i 点为起点的最后一条边的编号
//edges[j].next: 记录的是和编号为j的边有相同起点的上一条边的编号

struct edge {
    int e, v, next;
};

edge edges[100005];
int n, m, head[100005]; //如果是无向图就需要两倍，并用cnt记录

int main() {
    memset(head, -1, sizeof(head));
    cin >> n >> m;
    for (int i = 0; i < m; i++) {
        int s, e, v;
        cin >> s >> e >> v;
        //加边
        edges[i].e = e;
        edges[i].v = v;
        edges[i].next = head[s];
        head[s] = i; //以s为起点的最后一条边的编号为i
    }

    for (int i = 1; i <= n; i++) {
        cout << i << " : ";
        for (int j = head[i]; j != -1; j = edges[j].next) { // j为边的编号
            cout << "{" << edges[j].e << ", " << edges[j].v << "} ";
        }
        cout << endl;
    }

    return 0;
}

